<?php
namespace app\models;

use yii;
use yii\db\Query;

//出货表
class Shipment
{
    public $table;

    public function __construct()
    {
        $this->table = yii::$app->db->tablePrefix."shipment";
    }

    //查询业务员出货列表
    public function get_all_shipment_by_saleman($saleman, $p, $s, $where = [])
    {
        $db = new Query();
        $db->select('*')->from($this->table);
        if ($saleman) {
            $db->where(['saleman' => $saleman]);
        }
        return $db->orderBy(['date'=>SORT_DESC,'id'=>SORT_DESC])
            ->offset(($p-1)*$s)
            ->limit($s)
            ->all();
    }

    //分页大小
    public function get_shipment_size($saleman, $where = [])
    {
        $db = new Query();
        $db->select('count(id) as num')->from($this->table);
        if ($saleman) {
            $db->where(['saleman'=>$saleman]);
        }
        return $db->where(['saleman'=>$saleman])
            ->one();
    }

    //通过id搜索
    public function get_shipment_by_id($id)
    {
        $db = new Query();
        $info = $db->select('*')
            ->from($this->table)
            ->where(['id'=>$id])
            ->one();
        return $info;
    }
}
